PO-3412, PO-2948 Implementing exact offence code match, preventing early offence code submission#2384
Merged
stephenmagill merged 26 commits intomasterfrom Apr 13, 2026
Merged
PO-3412, PO-2948 Implementing exact offence code match, preventing early offence code submission#2384stephenmagill merged 26 commits intomasterfrom
stephenmagill merged 26 commits intomasterfrom
Conversation
iamfrankiemoran
requested changes
Mar 31, 2026
Contributor
iamfrankiemoran
left a comment
There was a problem hiding this comment.
There is also a P1 issue via codex /review:
- [P1] Reject ambiguous exact-code matches — /Users/iamfrankiemoran/Documents/GitHub/opal-frontend/src/app/flows/fines/fines-mac/fines-mac-offence-details/services/fines-mac-offence-details.service.ts:149-152
When the lookup response contains the same CJS code more than once (for example, the existing offence ref-data mock already has GMMET001 against multiple business units), findExactOffenceMatch() will return the first row and initOffenceCodeListener()
will now clear the validation error and persist that row's offence_id. That turns an ambiguous lookup into a seemingly valid selection, and the chosen offence_id is what later gets sent in the MAC account payload, so duplicated codes can be saved
against the wrong offence record. This should only be treated as a match when the exact code is unique, or after disambiguating by business unit/date.
…d to disambiguate duplicate matches.
Arnabsubedi233
requested changes
Apr 7, 2026
iamfrankiemoran
requested changes
Apr 8, 2026
iamfrankiemoran
approved these changes
Apr 8, 2026
iamfrankiemoran
requested changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira link
See PO-3412,
PO-2948
Change description
Problem
PO-3412
Entering an offence code that is valid itself but also has related sub-codes could show an incorrect “Offence not found” message in Manual Account Creation.
Example:
CD71039CD71039,CD71039A,CD71039B,CD71039CCD71039is present in the response and the intended code to displayThis created an inconsistent journey because the review screen could still appear to show the correct offence later in the flow.
PO-2948
Entering an invalid offence code that fits basic validation by being 7 or 8 characters long, e.g. "TESTTEST", and immediately submitting the code before the application has had the chance to receive the backend response will allow the user to continue with an invalid code.
Cause
PO-3412
The cause of this was the conditional logic on
fines-mac-offence-code-hint.component.htmlset to display the retrieved offence code only whenresponse.count === 1. This means when a code not only pulls itself down from the backend but also all sub-codes the response count is more than 1 and this condition defaults the page to show "No offence found".In general multiple codes being returned in the response hasn't been accounted and these issues affected a few places:
That affected a few places:
offence_idwhenresponse.count === 1count === 1refData[0], which only worked if the exact match happened to be the first returned itemSo for multi-result responses containing a valid exact match, we could:
offence_idunsetPO-2948
When a user entered a lookup-length offence code, the form kicked off async backend validation, but there was a window before the response came back where the form could still be submitted. If the user submitted during that gap, the offence code had not yet been marked invalid and the unresolved lookup had not blocked submission, so an invalid code could slip through.
Solution
PO-3412
The primary fix here is to change the condition that determines between displaying the offence code or error. Instead of checking for the number of responses, we should be looking for an exact match from all codes in a given response.
Fixes:
offence_idfrom that exact matchThis keeps the behaviour consistent across:
PO-2948
When the offence code changes, the form now marks lookup-length values as validation-pending straight away and
clears the offence ID until a matching backend result resolves. On submit, the form explicitly checks whether
offence-code validation is still unresolved or whether the last lookup failed, retries failed lookups, and keeps the form invalid until the lookup either resolves to a valid offence or returns a definite invalid result.
Considerations
Testing done
Manual testing
Both reported cases have been manually tested after the described changes have been implemented and confirmed to be addressed.
Unit testing
The testing approach focused on the exact-match behaviour across the full offence-code journey: service tests were used to verify that when the API returns multiple related offences, the lookup only succeeds if one record exactly matches the user-entered code, including both the positive case (CD71039 returned alongside CD71039A/B/C) and the negative case where similar results are returned but no exact match exists; targeted component tests then confirmed that the same rule is reflected in the UI, so the offence hint panel and both review displays now show the correct offence title and “Offence found” state for exact matches, and continue to show “Offence not found” where no exact match is present, removing any dependency on response ordering.
The testing for preventing early offence code submission is implemented by unit tests in the shared offence-code listener service and in both affected form components. At a high level, the tests verify that lookup-length offence codes are marked as pending immediately, submission is blocked while validation is unresolved, failed lookups are retried on submit, stale async responses are ignored when users type quickly, and the pending state is cleared once a valid offence is resolved.
Security Vulnerability Assessment
CVE Suppression: Are there any CVEs present in the codebase (either newly introduced or pre-existing) that are being intentionally suppressed or ignored by this commit?
Checklist